<html>
<head>
{php}html_header_show();{/php}

<link rel="stylesheet" href="{$css_header}" type="text/css">
{literal}

<script language="JavaScript">

function clear_vars() {
  document.report.var1.value = "";
  document.report.var2.value = "";
}

function dopopup(aurl) {
 top.restoreSession();
 window.open(aurl, '_blank', 'width=750,height=550,resizable=1,scrollbars=1');
}

</script>

{/literal}
</head>
<body bgcolor="{$STYLE.BGCOLOR2}">

<div id="reports_list">
{php}
//get directories that might contain reports 
$reportsdir = './myreports/';
if (is_dir($reportsdir)) {
  $folder_array = array();
  if ($handle = opendir($reportsdir)) {
      while (false !== ($file = readdir($handle))) {
        if ($file != '.' && $file != '..' && is_dir($reportsdir.$file)) {
          $folder_array[$file] = array();
        }
      }
      closedir($handle);
  }
  
  //fill elements of $folder_array with the php files in each directory
  foreach ($folder_array as $key => $val) {
    $reportsubdir = $reportsdir.$key.'/';
    if ($handle = opendir($reportsubdir)) {
        while (false !== ($file = readdir($handle))) {
          if ($file != '.' && $file != '..' && substr($file,-4,4) == '.php') {
          //if ($file != '.' && $file != '..') {
            $filename = substr($file,0,strlen($file)-4);
            $folder_array[$key][$filename] = $GLOBALS['webroot'].'/interface/reports/myreports/'.$key.'/'.$file;
          }
        }
        closedir($handle);
    }
  }
  //generate drop down menus
  echo "<FORM METHOD=POST NAME=choose>\n";
  foreach ($folder_array as $title => $link) {
    if (count($link) > 0) { //only create menus for those subdirectories with php reports in them
       echo "<select name=" . $title. " onchange='top.restoreSession();window.open(document.choose.".$title.".options[document.choose.".$title.".selectedIndex].value);".$title.".selectedIndex = 0'>\n";
       echo "<option value=".$GLOBALS['webroot'].'/interface/reports/myreports/'.$title.">".xl($title)."</option>\n";
       foreach ($link as $eachlink_name => $eachlink) {
         echo "<option value='".$eachlink."'>".xl($eachlink_name)."</option>\n";
       }
       echo "</select><br>\n";
    }
  }
  echo "</FORM>\n";
  
  //now deal with the reports that are just under myreports, not organized into subdirectories
  $reportsdir = './myreports/';
  $dir_array = array();
  if ($handle = opendir($reportsdir)) {
      while (false !== ($file = readdir($handle))) {
        if ($file != '.' && $file != '..' && substr($file,-4,4) == '.php') {
          $filename = substr($file,0,strlen($file)-4);
          array_push($dir_array,"<a href='$reportsdir$file' target='_blank' onclick='top.restoreSession()'>".xl($filename)."</a><br>\n");
        }
      }
      closedir($handle);
  }
  //print the links for reports under myreports
  foreach($dir_array as $var) {
    echo $var;
  }
}
{/php}

<ul>
<li>
<a href="custom_report_range.php" target="_blank" onclick="top.restoreSession()">{xl t='Superbill Report'}</a>
</li><li>
<a href="appointments_report.php" target="_blank" onclick="top.restoreSession()">{xl t='Appointments Report'}</a>
</li><li>
<a href="encounters_report.php" target="_blank" onclick="top.restoreSession()">{xl t='Encounters Report'}</a>
<br/>
</li><li>
<a href="appt_encounter_report.php" target="_blank" onclick="top.restoreSession()">{xl t='Appointments-Encounters Report'}</a>
</li>
{php} if (! $GLOBALS['simplified_demographics']) { {/php}
<li>
<a href="insurance_allocation_report.php" target="_blank" onclick="top.restoreSession()">{xl t='Patient Insurance Distribution Report'}</a>
</li><li>
<a href="../billing/indigent_patients_report.php" target="_blank" onclick="top.restoreSession()">{xl t='Indigent Patients Report'}</a>
</li><li>
<a href="unique_seen_patients_report.php" target="_blank" onclick="top.restoreSession()">{xl t='Unique Seen Patients Report'}</a>
</li><li>
<a href="patient_list.php" target="_blank" onclick="top.restoreSession()">{xl t='Patient List'}</a>
</li>
{php} } {/php}

{php} if (! $GLOBALS['weight_loss_clinic']) { {/php}
<li>
<a href="front_receipts_report.php" target="_blank" onclick="top.restoreSession()">{xl t='Front Office Receipts Report'}</a>
</li>
{php} } {/php}

<li>
<a href="prescriptions_report.php" target="_blank" onclick="top.restoreSession()">{xl t='Prescriptions Report'}</a>
</li><li>
<a href="sales_by_item.php" target="_blank" onclick="top.restoreSession()">{xl t='Sales by Product Report'}</a>
</li><li>
<a href="collections_report.php" target="_blank" onclick="top.restoreSession()">{xl t='Collections Report'}</a>
</li><li>
<a href="referrals_report.php" target="_blank" onclick="top.restoreSession()">{xl t='Referrals Report'}</a>
</li><li>
<a href="non_reported.php" target="_blank" onclick="top.restoreSession()">{xl t='Non Reported Report'}</a>
</li>

{php} if ($GLOBALS['inhouse_pharmacy']) { {/php}
<li>
<a href="destroyed_drugs_report.php" target="_blank" onclick="top.restoreSession()">{xl t='Destroyed Drugs Report'}</a>
</li>
{php} } {/php}
<li>
<a href="receipts_by_method_report.php" target="_blank" onclick="top.restoreSession()">{xl t='Receipts by Payment Method Report'}</a>
</li>
<!-- </ul> -->
<li>
<a href="chart_location_activity.php" target="_blank" onclick="top.restoreSession()">{xl t='Chart Check-in/out Activity Report'}</a>
</li>
<li>
<a href="charts_checked_out.php" target="_blank" onclick="top.restoreSession()">{xl t='Charts Checked Out'}</a>
</li>
<li>
<a href="services_by_category.php" target="_blank" onclick="top.restoreSession()">{xl t='Services by Category'}</a>
</li>
{php}
 if ($GLOBALS['athletic_team']) {
  echo "<li>\n";
  echo "<a href='javascript:dopopup(\"players_report.php\")'>Team Roster</a>\n";
  echo "</li><li>\n";
  echo "<a href='javascript:dopopup(\"absences_report.php\")'>Days and Games Missed</a>\n";
  echo "</li><li>\n";
  echo "<a href='javascript:dopopup(\"football_injury_report.php\")'>Football Injury Reports</a>\n";
  echo "</li><li>\n";
  echo "<a href='javascript:dopopup(\"injury_overview_report.php\")'>Injury Overview Report</a>\n";
  echo "</li>\n";
 }
 if (!empty($GLOBALS['code_types']['IPPF'])) {
  echo "<li>\n";
  echo "<a href='javascript:dopopup(\"ippf_statistics.php?t=i\")'>IPPF Statistics</a>\n";
  echo "</li><li>\n";
  echo "<a href='javascript:dopopup(\"ippf_statistics.php?t=m\")'>MA Statistics</a>\n";
  echo "</li>\n";
 }
{/php}

</ul>

<a href="{$printable_link}" target="_blank" onclick="top.restoreSession()">[{xl t='printable'}]</a>
&nbsp;
<br/>
<form name="report" action="index.php" method="get" onsubmit="return top.restoreSession()">
<table>
	<tr>
		<td>{xl t='Reports'}:</td>
		<td>{html_options onChange="clear_vars()" name="query_id" selected=$query_id options=$queries}</td>
		<td>&nbsp;&nbsp;</td>
		<td>{xl t='Var1'}:&nbsp;<input size="10" type="text" value="{$var1}" name="var1"></td>
		<td>&nbsp;&nbsp;</td>
		<td>{xl t='Var2'}:&nbsp;<input size="10" type="text" value="{$var2}"name="var2"></td>
		<td>&nbsp;&nbsp;</td>
		<td>{xl t='Show'}:&nbsp;</td>
		<td>{html_options name="show" selected=$show options=$show_options}<input type="submit" value="{xl t='Go'}"></td>
	</tr>
	<tr>
		<td colspan="5"><br><h2>{$title}&nbsp;&nbsp;&nbsp;&nbsp;{$smarty.now|date_format:"%A, %B %e, %Y"}</h2></td>
	</tr>
	<tr>
		<td colspan="5">
		{if is_object($pager)}
			{$pager->render($show)}
		{/if}
		</td>
	</tr>
</table>
</form>
</div> <!-- end of reports_list -->
</body>
</html>
